using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LevelManager : Singleton<LevelManager>
{
    [SerializeField] private int lives = 10; // 玩家生命值

    public int TotalLives { get; set; }
    public int CurrentWave { get; set; }

    private void Start()
    {
        TotalLives = lives;
        CurrentWave = 1;
    }

    // 减少生命值
    private void ReduceLives(Enemy enemy)
    {
        TotalLives--;
        if (TotalLives <= 0)
        {
            TotalLives = 0;
            //游戏结束
            GameOver();
        }
    }

    private void GameOver()
    {
        UIManager.Instance.ShowGameOverPanel();
    }

    private void WaveCompleted()
    {
        CurrentWave++;
    }

    // 当脚本组件启用时注册事件监听
    private void OnEnable()
    {
        Enemy.OnEndReached += ReduceLives; // 当敌人到达终点时减少生命值
        Spawner.OnWaveCompleted += WaveCompleted;
    }

    // 当脚本组件禁用时取消事件监听
    private void OnDisable()
    {
        Enemy.OnEndReached -= ReduceLives; // 取消对减少生命值事件的监听
        Spawner.OnWaveCompleted -= WaveCompleted;
    }
}

